package com.ywl.designpattern.composite;

/**
 * 4. 客户端代码
 * @author yuwl
 * @description 最后,我们可以使用这个组合模式来创建和操作文件系统结构:
 * @since 2024-07-03 10:50
 */
public class CompositePatternDemo {

    public static void main(String[] args) {
        FileSystemComponent root = new Directory("Root");

        FileSystemComponent home = new Directory("home");
        FileSystemComponent documents = new Directory("Documents");

        FileSystemComponent file1 = new File("file1.txt");
        FileSystemComponent file2 = new File("file2.txt");
        FileSystemComponent file3 = new File("file3.txt");

        root.add(home);
        root.add(documents);

        home.add(file1);
        documents.add(file2);
        documents.add(file3);

        //显示整个文件系统结构
        root.display();
    }
}
